#include "Menu.h"

int Menu::getChoice(){
    
    cout << "欢迎来到智能家居管理系统" << endl;
    int choice;
    cout << "1.登录" << endl;
    cout << "2.注册" << endl;
    cin>> choice;
    return choice;
    
}
int Menu::getLoginChoice(){
    cout << "1.普通用户" << endl;
    cout << "2.管理员" << endl;
    int choice;
    cin >> choice;
    return choice;
}
int Menu::getRegisterChoice(){
    cout << "1.普通用户" << endl;
    cout << "2.管理员" << endl;
    int choice;
    cin >> choice;
    return choice;
}

int Menu::getManagerChoice(){
    cout << "1.查看所有设备" << endl;
    cout << "2.查看所有日志" << endl;
    cout << "3.管理用户" << endl;
    cout << "4.操作设备" << endl;
    cout<< "5.返回上一层" << endl;
    int choice;
    cin >> choice;
    return choice;
}
int Menu::getUserChoice(){
    cout << "1.查看设备" << endl;
    cout << "2.操作设备" << endl;
    cout << "3.查看日志" << endl;
    cout << "4.返回上一层" << endl;
    int choice;
    cin >> choice;
    return choice;
}
int Menu::getDeviceChoice(){
    cout << "1.添加设备" << endl;
    cout << "2.删除设备" << endl;
    cout << "3.更新日志" << endl;
    cout << "4.返回上一层" << endl;
    int choice;
    cin >> choice;
    return choice;
}

int Menu::getDeviceTypeChoice(){
    cout << "1.灯具" << endl;
    cout << "2.温控器" << endl;
    cout << "3.摄像头" << endl;
    cout << "4.插座" << endl;
    cout<< "5.返回上一层" << endl;
    int choice;
    cin >> choice;
    return choice;
}
void Menu::displayMenu( Operation operation,Role role){

    string username;
    string password;
    UserManager userM;
    User*users=nullptr;
    DeviceManager deviceM;
    LogManager logM;
    bool managerChoice=true;
    bool managerChoiceAdd=true;
    bool userChoice=true;
    bool userChoiceAdd=true;
    switch (operation) {
        case Operation::OPLOGIN:
            
            cout << "欢迎来到登录界面" << endl;
            cout << "请输入用户名：" << endl;
            cin >> username;
            cout << "请输入密码：" << endl;
            cin >> password;
            users= userM.loginUser(username,password);
            if (users->getRole()==ROLEADMIN)
            {
                while (managerChoice)
                {
                    /* code */
                       /* code */
                //管理员
                
                switch (getManagerChoice())
                {
                    case 1:
                        /* code */
                            deviceM.getDevice(users->getId(),users->getRole());
                        break;
                    case 2:
                        /* code */
                            logM.getLogs(users->getId(),users->getRole());
                        break;
                    case 3:
                        /* code */
                        break;
                    case 4:
                        /* code */
                            while (managerChoiceAdd)
                            {
                                /* code */
                                switch (getDeviceChoice())
                                {
                                    case 1:
                                        /* code */
                                            deviceM.addDevice(getDeviceTypeChoice(),"wu");
                                            logM.addLog("操作",0,users->getId(),"添加设备");
                                        break;
                                    case 2:
                                        /* code */
                                            deviceM.deleteDevice(1);
                                            logM.addLog("操作",0,users->getId(),"删除设备");
                                        break;
                                    case 3:
                                        /* code */
                                        break;
                                    case 4:
                                        /* code */
                                        managerChoiceAdd=false;
                                        break;
                                
                                    default:
                                    break;
                            }
                            }
                            
                            
                        break;
                        case 5:
                            managerChoice=false;
                        break;
                    default:
                        break;
                }
                }
                
             
            }else{
                //普通用户
                getUserChoice();
            }
            
            break;
        case Operation::OPREGISTER:
            cout << "欢迎来到注册界面" << endl;
            cout << "请输入用户名：" << endl;
            cin >> username;
            cout << "请输入密码：" << endl;
            cin >> password;
            userM.registerUser(username,password,role);
            break;
        case Operation::OPMANAGER:
            cout << "欢迎来到管理员界面" << endl;
            break;
        case Operation::OPUSER:
            cout << "欢迎来到普通用户界面" << endl;
           break;
    }
}
